layui.use('form', function () {
    var form = layui.form;
    var college = $("#college"),
        profession = $("#profession");

    //向select中 追加内容
    //初始将省份数据赋予
    for (var i = 0; i < collegeList.length; i++) {
        addEle(college, collegeList[i].name);
        //alert("aaa");
    }

    function addEle(ele, value) {
        var optionStr = "";
        optionStr = "<option value=" + value + " >" + value + "</option>";
        ele.append(optionStr);
    }

    //赋予完成 重新渲染select
    form.render('select');

    //移除select中所有项 赋予初始值
    function removeEle(ele) {
        ele.find("option").remove();
        var optionStar = "<option value=" + "0" + ">" + "请选择" + "</option>";
        ele.append(optionStar);
    }

    var collegeText,
        professionText;

    //选定省份后 将该省份的数据读取追加上
    form.on('select(college)', function (data) {
        collegeText = data.value;
        $.each(collegeList, function (i, item) {
            if (collegeText == item.name) {
                professionItem = i;
                return professionItem;
            }
        });
        removeEle(profession);
        $.each(collegeList[professionItem].professionList, function (i, item) {
            if (professionText == item.name) {
                //for (var n = 0; n < item.length; n++) {
                addEle(profession, item);
                //}
            }
        });
        //重新渲染select
        form.render('select');
    })
})